import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * @since 2018-10-28

 */
import { getResponse } from 'utils/utils';
import { loadTemplate as _loadTemplate, loadDataSource as _loadDataSource, validateData as _validateData, importData as _importData, updateOne as _updateOne, queryStatus as _queryStatus } from "../services/commentImportService";
export default {
  namespace: 'comment',
  state: {
    template: {},
    detailList: [],
    detailData: {},
    batch: '',
    isloading: false,
    prefixPatch: ''
  },
  effects: {
    loadTemplate: /*#__PURE__*/_regeneratorRuntime.mark(function loadTemplate(_ref, _ref2) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function loadTemplate$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call;
              _context.next = 4;
              return call(_loadTemplate, payload);

            case 4:
              res = _context.sent;
              return _context.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context.stop();
          }
        }
      }, loadTemplate);
    }),
    loadDataSource: /*#__PURE__*/_regeneratorRuntime.mark(function loadDataSource(_ref3, _ref4) {
      var templateCode, batch, prefixPatch, params, call, put, res, dataSource;
      return _regeneratorRuntime.wrap(function loadDataSource$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              templateCode = _ref3.templateCode, batch = _ref3.batch, prefixPatch = _ref3.prefixPatch, params = _ref3.params;
              call = _ref4.call, put = _ref4.put;
              _context2.next = 4;
              return call(_loadDataSource, templateCode, batch, prefixPatch, params);

            case 4:
              res = _context2.sent;

              if (!getResponse(res)) {
                _context2.next = 10;
                break;
              }

              dataSource = (res || []).map(function (n) {
                return _objectSpread({
                  id: n.id,
                  errorMsg: n.errorMsg,
                  imported: n.imported,
                  validated: n.validated
                }, JSON.parse(n.data));
              });
              _context2.next = 9;
              return put({
                type: 'commentUpdateState',
                payload: {
                  batch: batch
                }
              });

            case 9:
              return _context2.abrupt("return", dataSource);

            case 10:
            case "end":
              return _context2.stop();
          }
        }
      }, loadDataSource);
    }),
    validateData: /*#__PURE__*/_regeneratorRuntime.mark(function validateData(_ref5, _ref6) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function validateData$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call;
              _context3.next = 4;
              return call(_validateData, payload);

            case 4:
              res = _context3.sent;
              return _context3.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context3.stop();
          }
        }
      }, validateData);
    }),
    importData: /*#__PURE__*/_regeneratorRuntime.mark(function importData(_ref7, _ref8) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function importData$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call;
              _context4.next = 4;
              return call(_importData, payload);

            case 4:
              res = _context4.sent;
              return _context4.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context4.stop();
          }
        }
      }, importData);
    }),
    updateOne: /*#__PURE__*/_regeneratorRuntime.mark(function updateOne(_ref9, _ref10) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function updateOne$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref9.payload;
              call = _ref10.call;
              _context5.next = 4;
              return call(_updateOne, payload);

            case 4:
              res = _context5.sent;
              return _context5.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context5.stop();
          }
        }
      }, updateOne);
    }),
    queryStatus: /*#__PURE__*/_regeneratorRuntime.mark(function queryStatus(_ref11, _ref12) {
      var prefixPatch, params, call, res;
      return _regeneratorRuntime.wrap(function queryStatus$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              prefixPatch = _ref11.prefixPatch, params = _ref11.params;
              call = _ref12.call;
              _context6.next = 4;
              return call(_queryStatus, prefixPatch, params);

            case 4:
              res = _context6.sent;
              return _context6.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context6.stop();
          }
        }
      }, queryStatus);
    })
  },
  reducers: {
    commentUpdateState: function commentUpdateState(state, action) {
      return _objectSpread(_objectSpread({}, state), action.payload);
    }
  }
};